from django.shortcuts import render

from areas.serializers import AreasSerializer, AddressSerializer
from user.models import Address
from .models import Area
# Create your views here.
from rest_framework.generics import ListAPIView,CreateAPIView
from rest_framework.views import APIView
from rest_framework_extensions.cache.mixins import CacheResponseMixin



class AreasView(CacheResponseMixin,ListAPIView):
    serializer_class = AreasSerializer
    queryset = Area.objects.filter(parent=None)



class AreaView(CacheResponseMixin,ListAPIView):
    serializer_class = AreasSerializer

    # 重写get_queryset（）方法，获取pk值，返回查询集
    def get_queryset(self):
        # view()可以获取路由中的pk值．
        pk = self.kwargs['pk']
        return Area.objects.filter(parent_id=pk)


    # post　新增地址，address　

class AddressView(CreateAPIView,ListAPIView):
    # 底层实现新增
    serializer_class = AddressSerializer
    queryset =Address.objects.filter(is_deleted = False)









